package com.zhi.service.impl;

import com.zhi.dao.FacultyRepository;
import com.zhi.entity.Faculty;
import com.zhi.service.FacultyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FacultyServiceImpl implements FacultyService {
	
	@Autowired
	private FacultyRepository facultyRepository;

	@Override
	public List<Faculty> getEntityList() {
		return facultyRepository.findAll();
	}
	
	@Override
	public List<Object[]> getEntityListWithCodeName() {
		return facultyRepository.getEntityListWithCodeName();
	}
	

	@Override
	public Page<Faculty> getEntityListWithCodeName(Pageable pageable) {
		return facultyRepository.getEntityListWithCodeName(pageable);
	}

	@Override
	public Faculty getOne(String facultyId) {
		return facultyRepository.getOne(facultyId);
	}
	
	@Override
	public List<Faculty> findAll(Faculty faculty) {
		Example<Faculty> example =Example.of(faculty);
		return facultyRepository.findAll(example);
	}

	@Override
	public void save(Faculty Faculty) {
		facultyRepository.save(Faculty);
	}

	@Override
	public void edit(Faculty Faculty) {
		facultyRepository.save(Faculty);
		
	}

	@Override
	public void delete(String facultyId) {
		facultyRepository.deleteById(facultyId);
	}

	@Override
	public Integer count(Faculty Faculty) {
		Example<Faculty> example =Example.of(Faculty);
		return (int)facultyRepository.count(example);
	}


}
